<!DOCTYPE html>
<html lang="en" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <link rel="stylesheet" href="/layui/css/layui.css">
  <link rel="stylesheet" href="/css/custom.form.css">
</head>
<body>
<div class="panel panel-default operation" hidden>
    <div class="panel-heading title"></div>
    <div class="layui-card-body">
        <form class="layui-form " action="" lay-filter="info" style="width: 700px;margin-top: 10px">
            <input name="id" hidden/>
            <div class="layui-form-item">
                <label class="layui-form-label">客户名称</label>
                <div class="layui-input-block">
                    <input type="khname" name="khname" placeholder="请输入客户名称" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">联系人</label>
                <div class="layui-input-block">
                    <input type="lxr" name="lxr" placeholder="请输入联系人" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">联系电话</label>
                <div class="layui-input-block">
                    <input type="lxdh" name="lxdh" placeholder="请输入联系电话" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">其他电话</label>
                <div class="layui-input-block">
                    <input type="ssxs" name="qtdh" placeholder="多个电话时，用；分隔" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">客户来源</label>
                <div class="layui-input-block">
                    <select id="khlySCF" name="khly">
                        <option value="">请选择客户来源</option>
                    </select>
                </div>

            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">意向度</label>
                <div class="layui-input-block">
                    <select id="kujbSCF" name="khjb">
                        <option value="">请选择意向度</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <input type="bz" name="bz" placeholder="请输入备注" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="submit">保存</button>
                    <button class="layui-btn layui-btn-primary" id="btn_cancel">返回</button>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="panel panel-default operationeidt" hidden>
    <div class="panel-heading title"></div>
    <div class="layui-card-body">
        <form class="layui-form " action="" lay-filter="infoeidt" style="width: 700px;margin-top: 10px">
            <div class="layui-form-item">
                <label class="layui-form-label">公司名称</label>
                <div class="layui-input-block">
                    <input type="text" name="gcmcA" class="layui-input" readonly>
                </div>
            </div>
            <input name="id" hidden/>
<!--            <div class="layui-form-item">-->
                <div class="layui-form-item">
                    <label class="layui-form-label">负责人</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" class="layui-input" readonly>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">创建时间</label>
                    <div class="layui-input-block">
                        <input type="text" name="cjtime"  class="layui-input" readonly>
                    </div>
                </div>

<!--            </div>-->


<!--            <div class="layui-form-item">-->
                <div class="layui-form-item">
                    <label class="layui-form-label">更新时间</label>
                    <div class="layui-input-block">
                        <input type="text" name="updatetime" class="layui-input"readonly>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">当前状态</label>
                    <div class="layui-input-block">
                        <input type="text" name="state" class="layui-input"readonly>
                    </div>
                </div>
<!--            </div>-->

            <label class="layui-form-label">基本情况</label>

            <div class="layui-form-item">
                <label class="layui-form-label">客户名称</label>
                <div class="layui-input-block">
                    <input type="text" name="khname"
                           class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">联系人</label>
                <div class="layui-input-block">
                    <input type="text" name="lxr" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">联系电话</label>
                <div class="layui-input-block">
                    <input type="text" name="lxdh"  class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">其他电话</label>
                <div class="layui-input-block">
                    <input type="text" name="qtdh"
                           class="layui-input">
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">客户来源</label>
                <div class="layui-input-block">
                    <select id="khlySCFeidt" name="khly" readonly>
                        <option value="">请选择客户来源</option>
                    </select>
                </div>

            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">意向度</label>
                <div class="layui-input-block">
                    <select id="kujbSCFeidt" name="khjb">
                        <option value="">请选择意向度</option>
                    </select>
                </div>

            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">入库时间</label>
                <div class="layui-input-block">
                    <input type="datetime-local" name="rktime"  class="layui-input"readonly>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-inline">
                    <label class="layui-form-label">去电次数</label>
                    <div class="layui-input-block">
                        <input type="text" name="qdcs"  class="layui-input"readonly>
                    </div>
                </div>
                <div class="layui-input-inline">
                    <label class="layui-form-label">跟进记录</label>
                    <div class="layui-input-block">
                        <input type="text" name="gjjl"  class="layui-input"readonly>
                    </div>
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">最后跟进时间</label>
                <div class="layui-input-block">
                    <input type="datetime-local" name="zhgjStartDate"  class="layui-input"readonly>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">下次联系时间</label>
                <div class="layui-input-block">
                    <input type="datetime-local" name="xclxtime"  class="layui-input"readonly>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">流公海时间</label>
                <div class="layui-input-block">
                    <input type="datetime-local" name="lrghtime" class="layui-input"readonly>
                </div>
            </div>



            <div class="layui-form-item">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <input type="text" name="bz" placeholder="" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="submiteidt">保存</button>
                    <button class="layui-btn layui-btn-primary" id="btn_canceleidt">返回</button>
                </div>
            </div>

        </form>

    </div>
</div>

<div class="table_div">
  <div id="searchParam"  shiro:hasPermission="tWdkh:list">
    <div class="layui-form-item">
      <div class="layui-input-inline">
        <input type="text" id="company" class="layui-input"  autocomplete="off" placeholder="请输入公司名称">
      </div>
        <div class="layui-input-inline">
            <input type="text" id="lxr" class="layui-input"  autocomplete="off" placeholder="请输入联系人">
        </div>
        <div class="layui-input-inline">
            <input type="text" id="lxdh" class="layui-input"  autocomplete="off" placeholder="请输入联系电话">
        </div>
        <div class="layui-input-inline layui-form" id="khjbSCid" hidden>
            <select id="kujbSC">
                <option value="">请选择意向度</option>
            </select>
        </div>
        <div class="layui-input-inline layui-form" id="ssxsSCid" hidden>
            <select id="ssxsSC">
                <option value="">请选择所属销售</option>
            </select>
        </div>
        <div class="layui-input-inline layui-form" id="khlySCid" hidden>
            <select id="khlySC">
                <option value="">请选择客户来源</option>
            </select>
        </div>
        <div class="layui-input-inline layui-form">
            <input type="text" name="date" class="layui-input" id="test-range0" placeholder="请选择跟进时间">
        </div>
        <div class="layui-input-inline layui-form">
            <input type="text" name="date" class="layui-input" id="test-range1" placeholder="请选择入库时间">
        </div>
        <div class="layui-input-inline layui-form">
            <input type="text" name="date" class="layui-input" id="test-range2" placeholder="请选择流公海时间">
        </div>
      <div class="layui-input-inline ">
        <button class="layui-btn" onclick="search()"  id="search">查询</button>
        <!--        <button class="layui-btn"   id="export">导出全部</button>-->
          <button type="button" class="layui-btn" id="uploadFile-button" style="display:none">
              <i class="layui-icon">&#xe67c;</i>上传文件
          </button>

      </div>
    </div>
  </div>
  <table class="layui-table" id="showTable" lay-filter="showTable" ></table>
</div>
<script type="text/html" id="toolbar">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" lay-event="add"  shiro:hasPermission="tWdkh:add">添加客户</button>
    <button class="layui-btn layui-btn-sm" lay-event="zy">转移</button>
    <button class="layui-btn layui-btn-sm" lay-event="lrgh">扔入公海</button>
    <button class="layui-btn layui-btn-sm" lay-event="batchDeleted" shiro:hasPermission="tWdkh:delete">删除</button>
      <button class="layui-btn layui-btn-sm" lay-event="pldr" ><i class="layui-icon">&#xe67c;</i>批量导入</button>
      <button class="layui-btn layui-btn-sm" lay-event="khcc">客户查重</button>

<!--      <button type="button" class="layui-btn" id="uploadFile-button" >上传文件</button>-->

  </div>
</script>
<script type="text/html" id="tool">
  <a class="layui-btn layui-btn-xs" lay-event="hujiao" >呼叫</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" shiro:hasPermission="tWdkh:delete">删除</a>
</script>

<div id="zhuanyidata" hidden>
    <div class="panel panel-default operation2" >
        <div class="panel-heading title"></div>
        <div class="layui-card-body">
            <form class="layui-form " action="" lay-filter="info" style="width: 700px;margin-top: 10px">
                <input name="id" hidden/>
                <div class="layui-form-item">
                    <label class="layui-form-label">变更负责人</label>
                    <div class="layui-input-block">
                        <select id="zyusername">
                            <option value="">请选择负责人</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button type="submit" class="layui-btn" lay-submit="" lay-filter="submit2">确定</button>
                        <button  class="layui-btn layui-btn-primary" id="btn_cancelzhuanyi">返回</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>



<div class="table_divkhcc" hidden >
    <div id=""  >
        <div class="layui-form-item">
            <div class="layui-input-inline layui-form" >
                <select id="reType">
                    <option value="1">公司名称</option>
                    <option value="2">联系方式</option>
                </select>
            </div>
            <div class="layui-input-inline">
                <input type="text" id="repeat" class="layui-input"  autocomplete="off" placeholder="请输入">
            </div>

            <div class="layui-input-inline ">
                <button class="layui-btn" onclick="searchRepeat()"  id="searchRepeat">查重</button>
            </div>
        </div>
    </div>
    <table class="layui-table" id="showTableKhcc" lay-filter="showTable" ></table>
</div>
<div class="table_divqtkh" hidden >
    <table class="layui-table" id="showTableqtkh" lay-filter="showTable" ></table>
</div>
<script type="text/html" id="toolKhcc">
    <a class="layui-btn layui-btn-xs" lay-event="lingqu" >领取</a>
    <a class="layui-btn layui-btn-xs" lay-event="fenpei" >分配</a>
</script>
<script type="text/html" id="toolqtdh">
    <a class="layui-btn layui-btn-xs" lay-event="hujiaoqtdh" >呼叫</a>
</script>
</body>
</html>
<script src="/layui/layui.all.js"></script>
<script src="/js/core.util.js"></script>
<script src="/js/jquery.js"></script>
<script src="/js/common.js"></script>
<script>

    layui.use(['jquery', 'layer', 'form', 'table'], function () {
        var $ = layui.$,
            layer = layui.layer,
            form = layui.form,
            table = layui.table;

        // 时间戳的处理
        layui.laytpl.toDateString = function(d, format){
            var date = new Date(d || new Date())
                ,ymd = [
                this.digit(date.getFullYear(), 4)
                ,this.digit(date.getMonth() + 1)
                ,this.digit(date.getDate())
            ]
                ,hms = [
                this.digit(date.getHours())
                ,this.digit(date.getMinutes())
                ,this.digit(date.getSeconds())
            ];

            format = format || 'yyyy-MM-dd HH:mm:ss';

            return d ? format.replace(/yyyy/g, ymd[0])
                .replace(/MM/g, ymd[1])
                .replace(/dd/g, ymd[2])
                .replace(/HH/g, hms[0])
                .replace(/mm/g, hms[1])
                .replace(/ss/g, hms[2]) : '';
        };
        // 数字前置补零
        layui.laytpl.digit = function(num, length, end){
            var str = '';
            num = String(num);
            length = length || 2;
            for(var i = num.length; i < length; i++){
                str += '0';
            }
            return num < Math.pow(10, length) ? str + (num|0) : num;
        };

        // 渲染数据表格
        table.render({
            elem : '#dataTable'
            ,url : '/admin/admin/adminlist.html'
            ,cellMinWidth: 80
            ,page: {
                prev: '上一页',
                next: '下一页',
                layout: ['prev', 'page', 'next', 'skip', 'count', 'limit']
            }
            // ,toolbar: 'default'  // 开启顶部工具栏（默认模板）
            ,toolbar: '#toolbar' // 指定顶部工具栏模板
            // ,even: true  // 隔行背景
            ,title: '坐席表'  // 表格标题，用户导出数据文件名
            ,text: {  // 指定无数据或数据异常时的提示文本
                none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
            }
            ,id: 'dataTable'
            ,cols: [[  // 表格列标题及数据
                {title: '#', type: 'numbers'}
                ,{checkbox: true}
                // ,{field: 'id', width: 60, title: 'ID', sort: true, align: 'center'}
                ,{field: 'username', width: 150, title: '账号', sort: true, align: 'center'}
                ,{field: 'mobile', width: 150, title: '手机号',align: 'center'}
                ,{field: 'status', width: 80, title: '状态',sort: true,align: 'center', templet: '#status'}
                ,{field: 'name', width: 130, title: '姓名/联系人',align: 'center'}
                ,{field: 'company_name', width: 150, title: '公司名称',align: 'center',templet:function(data) {
                        if (data.company_name) {
                            return data.company_name;
                        } else if(data.admin) {
                            return data.admin.company_name;
                        }
                        return '';
                    }}
                ,{field: 'branch', width: 130, title: '部门',sort: true,align: 'center',templet:function(data) {
                        if (data.branch) {
                            return data.branch.name
                        } else {
                            var role = "1";
                            if (role == 1 && data.role_id != 4) {
                                return data.yuangong_count+' (坐席)';
                            }
                            return '';
                        }
                    }}
                ,{field: 'role_name', width: 100, title: '角色', align: 'center',templet:function(data) {
                        if(data.role) {
                            return data.role.name;
                        }
                        return '';
                    }}

                ,{field: 'minute', width: 100, title: '剩余分钟数', align: 'center'}
                ,{field: 'minute_money', width: 120, title: '当前分钟金额', align: 'center'}
                ,{field: 'create_time', width: 200, title: '创建时间', sort: true,align: 'center'}
                ,{field: 'reset_mintue_time', width: 150, title: '套餐重置时间', sort: true,  align: 'center'}
                ,{field: 'end_time', width: 120, title: '到期时间', sort: true,  align: 'center'}
                ,{field: 'market_name', width: 120, title: '销售姓名',  align: 'center'}
                ,{fixed: 'right', width: 300, title: '操作', align:'center', toolbar: '#barTool'}
            ]], done() {
                $(".layui-table").css("width", "100%");
                var role = "1";
                if (role == "4" || role == "6") {
                    $(".layui-table").find("[data-field='admin']").css("display","none");
                    $(".layui-table").find("[data-field='minute']").css("display","none");
                    $(".layui-table").find("[data-field='minute_money']").css("display","none");
                    $(".layui-table").find("[data-field='reset_mintue_time']").css("display","none");
                    $(".layui-table").find("[data-field='end_time']").css("display","none");
                    $(".layui-table").find("[data-field='market_name']").css("display","none");
                } else if(role == "7") {
                    $(".layui-table").find("[data-field='reset_mintue_time']").css("display","none");
                    $(".layui-table").find("[data-field='market_name']").css("display","none");
                }
            }
        });
        // 搜索功能
        var active = {
            reload: function(){
                var keywords = $('#keywords').val();
                var type = $('#type').val();
                var status = $('#state').val();
                var pid = $('#pid').val();
                var ztype = $('#ztype').val();
                var bind_id = $('#bind_id').val();
                var market_name = $('#market_name').val();
                //执行重载
                table.reload('dataTable', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        'keywords': keywords,
                        'type': type,
                        'status': status,
                        'pid': pid,
                        'ztype' : ztype,
                        'bind_id' : bind_id,
                        'market_name' : market_name
                    }
                }, 'data');
                $("#keywords").val(keywords)
                $("#type").val(type)
                $("#state").val(status)
                $("#pid").val(pid)
                $("#ztype").val(ztype)
                $("#bind_id").val(bind_id)
                $("#market_name").val(market_name)
            }
        };
        $('body').on('click','.search-btn', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        //头工具栏事件
        table.on('toolbar()', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            var ids = [];

            for (key in checkStatus.data) {
                ids[key] = checkStatus.data[key].id
            }
            if (ids.length == 0) {
                layer.msg('请选择坐席', {
                    time: 1000
                });
                return false;
            }
            switch(obj.event){
                case 'qi':
                    setStatus(ids, 1);
                    break;
                case 'jin':
                    setStatus(ids, 0);
                    break;
                case 'del':
                    layer.confirm('您确定要删除吗？', {
                        icon: 3
                    },function(index){
                        // 加载层
                        var loading = layer.msg('处理中，请稍后...', {
                            icon: 16,
                            shade: 0.5
                        });
                        $.ajax({
                            url: '/admin/admin/delete.html',
                            type: 'POST',
                            dataType: 'json',
                            data: {
                                'id' : ids
                            },
                            beforeSend: function(){},
                            success: function(res){
                                layer.close(loading);
                                if (res.status == 1) {
                                    layer.msg(res.message, {
                                        time: 1000
                                    },function(){
                                        window.location.reload();
                                    });
                                } else if (res.status == 0) {
                                    layer.alert(res.message, {
                                        icon: 2,
                                        skin: 'layer-ext-moon'
                                    },function(){
                                        parent.window.location.reload();
                                        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                        parent.layer.close(index);
                                    });
                                }
                            }
                        });
                    });
                    break;
            };
        });

        // 监听行内工具栏
        table.on('tool(dataTable)', function (obj) {
            var e = obj.event;
            var data = obj.data;
            if ( e === 'edit' ) {
                layer.open({
                    type: 2,
                    title: '<i class=iconfont>&#xe7e0;</i> 编辑坐席',
                    area: ['700px', '500px'],
                    content: ['/admin/admin/edit.html?id=' + data.id, 'yes'],
                    skin: 'layui-layer-molv',
                    btn: ['保存', '取消'],
                    btnAlign: 'c',
                    shadeClose: true,
                    shade: 0.8,
                    yes: function(index, layero){
                        var submit = layero.find('iframe').contents().find("#submit");// #subBtn为页面层提交按钮ID
                        submit.click();// 触发提交监听
                        return false;
                    },
                    btn2:function (index,layero) {
                        layer.close(index);
                    }
                });
            } else if ( e === 'del') {
                layer.confirm('您确定要删除吗？', {
                    icon: 3
                },function(index){
                    // 加载层
                    var loading = layer.msg('处理中，请稍后...', {
                        icon: 16,
                        shade: 0.5
                    });
                    $.ajax({
                        url: '/admin/admin/delete.html',
                        type: 'POST',
                        dataType: 'json',
                        data: {
                            id : data.id
                        },
                        beforeSend: function(){},
                        success: function(res){
                            layer.close(loading);
                            if (res.status == 1) {
                                layer.msg(res.message, {
                                    time: 1000
                                },function(){
                                    window.location.reload();
                                });
                            } else if (res.status == 0) {
                                layer.alert(res.message, {
                                    icon: 2,
                                    skin: 'layer-ext-moon'
                                });
                            }
                        }
                    });
                });
            } else if( e == 'edit_minute') {
                layer.open({
                    type: 2,
                    title: '<i class=iconfont>&#xe7e0;</i> 编辑分钟数',
                    area: ['700px', '500px'],
                    content: ['/admin/admin/edit_minute.html?id=' + data.id, 'yes'],
                    skin: 'layui-layer-molv',
                    btn: ['保存', '取消'],
                    btnAlign: 'c',
                    shadeClose: true,
                    shade: 0.8,
                    yes: function(index, layero){
                        var submit = layero.find('iframe').contents().find("#submit");// #subBtn为页面层提交按钮ID
                        submit.click();// 触发提交监听
                        return false;
                    },
                    btn2:function (index,layero) {
                        layer.close(index);
                    }
                });
            } else if (e == 'bind') {
                var index = layer.open({
                    type: 2,
                    title: '<i class=iconfont>&#xe7c7;</i> 添加子账号',
                    area: ['700px', '500px'],
                    content: ['/admin/admin/bindadd.html?id=' + data.id, 'yes'],
                    skin: 'layui-layer-molv',
                    btn: ['立即提交', '重置'],
                    btnAlign: 'c',
                    shadeClose: true,
                    shade: 0.8,
                    yes: function(index, layero){
                        var submit = layero.find('iframe').contents().find("#submit");// #subBtn为页面层提交按钮ID
                        submit.click();// 触发提交监听
                        return false;
                    },
                    btn2:function (index,layero) {
                        var reset = layero.find('iframe').contents().find("#reset");// #subBtn为页面层提交按钮ID
                        reset.click();// 触发重置按钮
                        return false;
                    }
                });
            } else if (e == 'renewal') {
                var index = layer.open({
                    type: 2,
                    title: '<i class=iconfont>&#xe7c7;</i> 续费',
                    area: ['700px', '500px'],
                    content: ['/admin/admin/renewal.html?id=' + data.id, 'yes'],
                    skin: 'layui-layer-molv',
                    btn: ['立即提交', '重置'],
                    btnAlign: 'c',
                    shadeClose: true,
                    shade: 0.8,
                    yes: function(index, layero){
                        var submit = layero.find('iframe').contents().find("#submit");// #subBtn为页面层提交按钮ID
                        submit.click();// 触发提交监听
                        return false;
                    },
                    btn2:function (index,layero) {
                        var reset = layero.find('iframe').contents().find("#reset");// #subBtn为页面层提交按钮ID
                        reset.click();// 触发重置按钮
                        return false;
                    }
                });
            } else if (e == 'ecpid') {
                layer.open({
                    type: 2,
                    title: '<i class=iconfont>&#xe7e0;</i> 小号管理',
                    area: ['70%', '80%'],
                    content: ['/admin/ecpid/index.html?id=' + data.id+'&type=1', 'yes'],
                    skin: 'layui-layer-molv',
                    btn: ['关闭'],
                    btnAlign: 'c',
                    shadeClose: true,
                    shade: 0.8,
                    yes: function(index, layero){
                        layer.close(index);
                    }
                });
            }
        });
        $('body').on('click','#add', function(){
            var index = layer.open({
                type: 2,
                title: '<i class=iconfont>&#xe7c7;</i> 添加坐席',
                area: ['700px', '500px'],
                content: ['/admin/admin/add.html', 'yes'],
                skin: 'layui-layer-molv',
                btn: ['立即提交', '重置'],
                btnAlign: 'c',
                shadeClose: true,
                shade: 0.8,
                yes: function(index, layero){
                    var submit = layero.find('iframe').contents().find("#submit");// #subBtn为页面层提交按钮ID
                    submit.click();// 触发提交监听
                    return false;
                },
                btn2:function (index,layero) {
                    var reset = layero.find('iframe').contents().find("#reset");// #subBtn为页面层提交按钮ID
                    reset.click();// 触发重置按钮
                    return false;
                }
            });
        });

        $('body').on('click','#add_agency', function(){
            var index = layer.open({
                type: 2,
                title: '<i class=iconfont>&#xe7c7;</i> 添加API代理查话单',
                area: ['700px', '500px'],
                content: ['/admin/admin/addagency.html', 'yes'],
                skin: 'layui-layer-molv',
                btn: ['立即提交', '重置'],
                btnAlign: 'c',
                shadeClose: true,
                shade: 0.8,
                yes: function(index, layero){
                    var submit = layero.find('iframe').contents().find("#submit");// #subBtn为页面层提交按钮ID
                    submit.click();// 触发提交监听
                    return false;
                },
                btn2:function (index,layero) {
                    var reset = layero.find('iframe').contents().find("#reset");// #subBtn为页面层提交按钮ID
                    reset.click();// 触发重置按钮
                    return false;
                }
            });
        });
    });

    // 设置显示状态
    function setStatus(ids, status) {
        // 加载层
        var loading = layer.msg('处理中，请稍后...', {
            icon: 16,
            shade: 0.2
        });
        $.ajax({
            url: "/admin/admin/setstatus.html",
            type: 'POST',
            dataType: 'json',
            data: {
                ids : ids,
                status : status
            },
            beforeSend: function(){},
            success: function (data) {
                layer.close(loading);
                if (data.status == 1) {
                    layer.msg(data.message, {
                        time: 1500
                    },function(){
                        window.location.reload();
                    });
                } else {
                    layer.alert(data.message, {
                        icon: 2
                    });
                }
            }
        });
    }

    layui.use(['form', 'jquery', 'laydate'], function () {
        var form = layui.form,
            $ = layui.$,
            laydate = layui.laydate;
        //年月选择器
        laydate.render({
            elem: '#test3'
            ,type: 'month'
        });
        // if ("1" == 7) {
        //     $("#minute").hide();
        //     $("#type_count").show();
        //     $("#end_time").show();
        // }
        form.on('select(type)', function(data){
            if(data.value == 1){
                $("#minute").show();
                // $("#minute_money").show();
                $("#type_count").hide();
                // $("#end_time").hide();
            } else {
                $("#minute").hide();
                // $("#minute_money").hide();
                $("#type_count").show();
                // $("#end_time").show();
            }
        });
        form.on('submit(submit)',function(data){
            // 加载层
            var loading = layer.msg('处理中，请稍后...', {
                icon: 16,
                shade: 0.2
            });
            $.ajax({
                url: '/admin/admin/doadd.html',
                type: 'POST',
                dataType: 'json',
                data: $('#form1').serialize(),
                beforeSend: function(){},
                success: function( data ){
                    layer.close( loading );
                    if ( data.status == 1 ) {
                        layer.msg(data.message, {
                            time: 1500
                        },function(){
                            parent.$('.search-btn').click();
                            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            parent.layer.close(index);
                        });
                    } else {
                        layer.alert(data.message, {
                            icon: 2,
                            skin: 'layer-ext-moon'
                        });
                    }
                }
            });
            return false;
        });
    });

</script>